/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.vip.page.service;

/**
 *
 * @author zhai
 */
public class Pager {

    public int totalRows; //总行数
    public int pageSize; //每页显示的行数
    public int currentPage; //当前页号
    public int totalPages; //总页数
    public int startRow; //当前页在数据库中的起始行

    public Pager() {
    }
    //自定义显示行数的构造方法

    public Pager(int totalRows, int pageSize) {
        this.pageSize = pageSize;
        this.totalRows = totalRows;
        this.totalPages = this.totalRows / this.pageSize;
        int mod = this.totalRows % this.pageSize;
        if (mod > 0) {
            this.totalPages++;
        }
        if (this.totalPages > 0) {
            this.currentPage = 1;
        } else {
            this.currentPage = 0;
        }
        this.startRow = 0;
    }

    public int getStartRow() {
        return this.startRow;
    }

    public int getTotalPages() {
        return this.totalPages;
    }

    public int getCurrentPage() {
        return this.currentPage;
    }

    public int getPageSize() {
        return this.pageSize;
    }

    public void setTotalRows(int totalRows) {
        this.totalRows = totalRows;
    }

    public void setStartRow(int startRow) {
        this.startRow = startRow;
    }

    public void setTotalPages(int totalPages) {
        this.totalPages = totalPages;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalRows() {
        return totalRows;
    }

    public void first() {
        if (this.currentPage >= 1) {
            this.currentPage = 1;
        } else {
            this.currentPage = 0;
        }
        this.startRow = 0;
    }

    public void previous() {
        if (this.currentPage <= 1) {
            return;
        }
        this.currentPage--;
        this.startRow = (this.currentPage - 1) * this.pageSize;
    }

    public void next() {
        if (this.currentPage == 0) {
            return;
        }
        if (this.currentPage < this.totalPages) {
            this.currentPage++;
        }
        this.startRow = (this.currentPage - 1) * this.pageSize;
    }

    public void last() {
        this.currentPage = this.totalPages;
        this.startRow = (this.currentPage - 1) * this.pageSize;
    }

    public void refresh(int _currentPage) {
        this.currentPage = _currentPage;
        if (this.currentPage > this.totalPages) {
            last();
        }
    }

    public void otherOperation() {
        this.startRow = (this.currentPage - 1) * this.pageSize;
    }
}
